# encoding=utf-8
import sys
from PyQt5 import QtWidgets,QtCore
from main import my_mainwindow,TrayIcon

class Dialog(QtWidgets.QMainWindow):
    def __init__(self,MainWindow,parent=None):
        super(Dialog, self).__init__(parent)
        self.MainWindow = MainWindow
    def closeEvent(self, event):
        reply = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Question, self.tr("提示"), self.tr("确定要退出吗？"), QtWidgets.QMessageBox.NoButton, self)
        yr_btn = reply.addButton(self.tr("是的我要退出"), QtWidgets.QMessageBox.YesRole)
        reply.addButton(self.tr("最小化到托盘"), QtWidgets.QMessageBox.NoRole)
        reply.exec_()
        if reply.clickedButton() == yr_btn:
            event.accept()
            QtWidgets.qApp.quit()
            # sys.exit(app.exec_())
        else:
            event.ignore()
            # 最小化到托盘
            mw.setWindowFlags(QtCore.Qt.SplashScreen | QtCore.Qt.FramelessWindowHint)
            mw.showMinimized()

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    mw = QtWidgets.QMainWindow()
    mw = Dialog(mw)
    # 调用setupUi方法，将设计好的界面-->主窗口上
    mw.setWindowFlags(QtCore.Qt.Window)
    ui = my_mainwindow(mw)
    mw.show()
    ti = TrayIcon(mw)
    ti.show()
    sys.exit(app.exec_())